/**
 * Created by IntelliJ IDEA.
 * User: scotthatcher
 * Date: Mar 25, 2010
 * Time: 3:02:50 PM
 * To change this template use File | Settings | File Templates.
 */
import acm.util.*;
import acm.program.*;
import java.io.*;

public class AskForFile extends ConsoleProgram{

    private BufferedReader openFile(String prompt){
        BufferedReader rd = null;

        while (rd==null){
            try{
                String filename = readLine(prompt);
                rd = new BufferedReader(new FileReader(filename));
            }
            catch (IOException ex) {
                println("Nice Try");
            }
        }
        return rd;
    }

    public void run(){
    setFont("Courier-24");
    BufferedReader rd = openFile("Please enter filename: ");

    try{
        while (true){
            String line = rd.readLine();
            if (line==null) break;
            println("Read line: (" + line + ")");
        }
        rd.close();
    } catch(IOException ex) {
        throw new ErrorException(ex);
    }
    }
}


